package com.lanju.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lanju.dao.IntroduceDao;
import com.lanju.entity.Introduce;
import com.lanju.entity.Message;
import com.lanju.service.IntroduceService;
@Service	
public class IntroduceServiceImpl implements IntroduceService {

	@Autowired
	IntroduceDao introduceDao;
	
	
	@Override
	@Transactional(value="financialmarketingTM", rollbackFor = Exception.class)
	public Map<String, Object> addIntroduce(Map<String,Object> map) {
		HashMap<String, Object> result=new HashMap<>();
		try {
			Introduce introduce=new Introduce();
			introduce.setCreateTime(new Date());
			introduce.setCreator(map.get("userCode").toString());
			introduce.setIntroduce(map.get("introduce").toString());
			introduceDao.addIntroduce(introduce);
			result.put("success", true);
		} catch (Exception e) {
			result.put("success", false);
			e.printStackTrace();
		}
		return result;
	}


	@Override
	@Transactional(value="financialmarketingTM", readOnly=true)
	public Map<String, Object> getIntroduceDetail(Map<String, Object> map) {
		 Map<String, Object> result=new HashMap<>();
		 System.out.println("id===="+map.get("id"));
		Introduce i=introduceDao.getIntroduceDetail(Integer.valueOf(((map.get("id")==null)?"1":map.get("id").toString())));
		result.put("rows", i);
		return result;
	}


	@Override
	@Transactional(value="financialmarketingTM", rollbackFor = Exception.class)
	public Map<String, Object> saveMessage(Map<String, Object> map) {
		Map<String, Object> result=new HashMap<>();
		Message m=new Message();
		m.setCreateTime(new Date());
		m.setM_Id(UUID.randomUUID().toString());
		m.setMessage(map.get("message").toString());
		m.setCreator(map.get("userCode")==null?"":map.get("userCode").toString());
		m.setType(Integer.valueOf(map.get("type").toString()));
		m.setCreateNmae(map.get("userName")==null?"":map.get("userName").toString());
		m.setStatus(0);
		try {
			introduceDao.saveMessage(m);
			result.put("success", true);
		} catch (Exception e) {
			result.put("success", false);
			e.printStackTrace();
		}
		return result;
	}


	@Override
	public Map<String, Object> getMessageList(Map<String, Object> map) {
		Map<String, Object> result=new HashMap<>();
		result.put("rows", introduceDao.getMessageList(Integer.valueOf(map.get("type").toString())));
		return result;
	}
	
	

}
